package dryven.view.engine.parser.scope;

import java.util.Collection;
import java.util.LinkedList;

import dryven.view.engine.parser.parts.CompiledViewPart;
import dryven.view.engine.parser.parts.TextPart;

public abstract class AbstractInstructionScope implements InstructionScope {

	private LinkedList<CompiledViewPart> _parts = new LinkedList<CompiledViewPart>();

	public AbstractInstructionScope() {
		super();
	}

	@Override
	public void addPart(CompiledViewPart part) {
		if(part instanceof TextPart && _parts.size()!=0) {
			CompiledViewPart lastPart = _parts.getLast();
			if(lastPart instanceof TextPart) {
				TextPart lastTextPart = (TextPart) lastPart;
				TextPart newTextPart = (TextPart) part;
				lastTextPart.append(newTextPart);
				return;
			}
		}
		_parts.add(part);
	}

	public Collection<CompiledViewPart> getParts() {
		return _parts;
	}

}